//
//  WDWorkOrderItemViewModel.m
//  wd-serviceapp
//
//  Created by Bin Tang on 2024/8/16.
//

#import "WDWorkOrderItemViewModel.h"

@implementation WDWorkOrderItemViewModel

- (void)initialize {
    [super initialize];
    
    _reqModel = [WDStationTaskSearchReqModel new];
    _reqModel.engineerId = @([EDSAppDelegateTool sharedInstance].userInfoModel.id);
    _reqModel.current = 1;
    _reqModel.size = 10;
}

- (void)setupData {
    
}

/// 请求数据
/// - Parameter completion: completion description
- (void)requestWithTaskSearch:(RequestCompletionBlock)completion {
    _reqModel.stationId = @([EDSAppDelegateTool sharedInstance].userInfoModel.stationId);
//    _reqModel.engineerId = @([EDSAppDelegateTool sharedInstance].userInfoModel.id);
    @weakify(self);
    WDStationTaskSearchRequest *request = [[WDStationTaskSearchRequest alloc] initWithModel:self.reqModel];
    [request startWithCompletionBlockWithSuccess:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        EDSRespondDataEntity *respond = request.responseModelObject;
        if (respond.code == EDS_NETWORK_SUCCESS) {
            if (self.reqModel.current == 1) {
                [self.dataList  removeAllObjects];
            }
            NSArray *list = respond.data;
            for (WDArrivalServiceItemModel *model in list) {
                model.searchType = self.reqModel.searchType;
            }
            [self.dataList addObjectsFromArray:list];
            if (list && list.count > 0) {
                self.reqModel.current += 1;
            }
        }
        [self sendResponseObject:request.responseModelObject completion:completion];
    } failure:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        [self sendResponseObject:request.responseModelObject completion:completion];
    }];
}

@end
